//
//  KKFollowCell.m
//  DoMi
//
//  Created by 康凯 on 2016/12/19.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKFollowCell.h"
#import "KKMyHttp.h"
#import "KKPersonalHomeVC.h"

@implementation KKFollowCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)initData:(KKFollowM *)data{
    self.followId=data.uid;
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:data.avatar] placeholderImage:[UIImage imageNamed:@"default_avater"]];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushAvatar)];
    [self.avatar addGestureRecognizer:tap];
    self.nickname.text=data.nickname;
    self.company.text=data.company;
    self.job.text=data.job[0];
    self.followBtn.selected=YES;
//    if([data.gzflag isEqualToString:@"0"]){
//        self.followBtn.selected=NO;
//    }else{
//        self.followBtn.selected=YES;
//    }
}
-(void)initFansData:(KKFollowM *)data{
    self.followId=data.uid;
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:data.avatar] placeholderImage:[UIImage imageNamed:@"default_avater"]];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushAvatar)];
    [self.avatar addGestureRecognizer:tap];
    self.nickname.text=data.nickname;
    self.company.text=data.company;
    self.job.text=data.job[0];
    if([data.gzflag isEqualToString:@"0"]){
        self.followBtn.selected=NO;
    }else{
        self.followBtn.selected=YES;
    }
}
#pragma mark 按钮--个人主页
-(void)pushAvatar{
    KKPersonalHomeVC *person=[[KKPersonalHomeVC alloc] init];
    person.expertId=self.followId;
    [[KKAppUtils getCurrentVisiableVC:self].navigationController pushViewController:person animated:YES];
}
#pragma mark 按钮--关注
- (IBAction)followClick:(id)sender {
    if(self.followBtn.isSelected){
        [self cancelFollow];
    }else{
        [self addFollow];
    }
    self.followBtn.selected=!self.followBtn.isSelected;
}

-(void)addFollow{
    [KKMyHttp addFollow:self.followId success:^(id data) {
        [KKAppUtils toast:@"关注成功"];
        self.followClickBlock();
    } failure:^(NSError *error) {
        
    }];
}
-(void)cancelFollow{
    [KKMyHttp cancelFollow:self.followId success:^(id data) {
        [KKAppUtils toast:@"取消关注成功"];
        self.followClickBlock();
    } failure:^(NSError *error) {
        
    }];
}
@end
